package com.lucenten.collect.gnss.controller;

import cn.quevo.common.annotation.RequiresPermissions;
import cn.quevo.common.entity.ResultEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.core.spring.SpringController;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import com.lucenten.collect.gnss.entity.SatelliteStation;
import com.lucenten.collect.gnss.entity.query.SatelliteStationQuery;
import com.lucenten.collect.gnss.service.SatelliteStationService;

import java.util.Map;

/**
 * 卫星台站信息 RestController
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2019/04/26 22:44:38
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@Api(value="卫星台站信息",  tags = "卫星台站信息")
@RestController("satelliteStationController")
@RequestMapping("/collect/")
public class SatelliteStationRestController extends SpringController{

    @Resource(name="satelliteStationService")
    private SatelliteStationService satelliteStationService;

    /**
     * 分页加载卫星台站信息
     *
     * @param satelliteStationQuery
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/26 22:44:38
     */
    @ApiOperation(value = "分页加载卫星台站信息", notes = "")
    @GetMapping(value="satelliteStation")
    @RequiresPermissions("collect:satelliteStation:list")
    public ResultEntity page(SatelliteStationQuery satelliteStationQuery){
        return satelliteStationService.getPage(satelliteStationQuery);
    }

    /**
     * 保存卫星台站信息
     *
     * @param satelliteStation
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/26 22:44:38
     */
    @ApiOperation(value = "保存卫星台站信息", notes = "")
    @PostMapping(value="satelliteStation")
    @RequiresPermissions("collect:satelliteStation:create")
    public ResultEntity create(@RequestBody SatelliteStation satelliteStation){
        if(satelliteStationService.create(satelliteStation) <= 0){
            return new ResultEntity(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }

    /**
     * 修改卫星台站信息
     *
     * @param satelliteStation
     * @param id
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/26 22:44:38
     */
    @ApiOperation(value = "修改卫星台站信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long", paramType = "path")
    })
    @PutMapping(value="satelliteStation/{id:\\d+}")
    @RequiresPermissions("collect:satelliteStation:update")
    public ResultEntity update(@RequestBody SatelliteStation satelliteStation, @PathVariable("id") Long id){
        if (StringUtils.isBlank(id)) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_UNSELECTED);
        }
        satelliteStation.setId(id);
        if (StringUtils.isBlank(this.satelliteStationService.update(satelliteStation))) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }
}
